package LeetCode;

import java.util.Scanner;

public class LC_011_ContainerWithMostWater {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] arr = sc.nextLine().trim().split("\\s+");
            int[] a = new int[arr.length];
            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(arr[i]);
            }
            System.out.println(maxArea_1(a));
        }
        sc.close();
    }

    private static int maxArea(int[] height) {
        int maxArea = Integer.MIN_VALUE;
        for (int i = 0; i < height.length - 1; i++) {
            for (int j = i + 1; j < height.length; j++) {
                maxArea = Math.max(maxArea, Math.min(height[i], height[j]) * (j - i));
            }
        }
        return maxArea;
    }

    private static int maxArea_1(int[] height) {
        int maxArea = 0;
        int i = 0, j = height.length - 1;
        while (i < j && i >= 0 && j <= height.length - 1) {
            maxArea = Math.max(maxArea, Math.min(height[i], height[j]) * (j - i));
            if (height[i] > height[j])
                j--;
            else
                i++;
        }
        return maxArea;
    }

}
